﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TiTi.tea.Comm;
using TiTi.tea.DAL;
using TiTi.tea.Dto;
using TiTi.tea.Model;

namespace TiTi.tea.BLL
{
    public class RoleInfoBLL
    {

        private RoleInfoDAL dal = new RoleInfoDAL();
        public IEnumerable<RoleInfo> Query(string RoleName, out int Total, int PageIndex, int PageSize)
        {
            var page = new PagePara(PageIndex, PageSize);
            if (string.IsNullOrEmpty(RoleName))
            {
                RoleName = "";
            }
            var data = dal.GetAll(o => o.RoleName.Contains(RoleName), o => o.CreateTime, page);
            Total = page.Total;
            return data;
        }
        public RoleInfo GetOne(int id)
        {
            return dal.GetOne(o => o.Id == id);
        }
        public bool Add(RoleInfo entity)
        {
            entity.CreateTime = DateTime.Now;
            return dal.Add(entity);
        }
        public bool Update(RoleInfo entity)
        {
            return dal.Update(entity);
        }
        public bool Delete(int Id)
        {
            var data = dal.GetOne(o => o.Id == Id);
            data.IsDelete = 1;
            return dal.Update(data);

        }

        public IEnumerable<RoleInfo> Getall()
        { 
            return dal.GetAll();
        }
    }
}
